<script setup lang="ts">
import { watch, type PropType } from 'vue';

import i18n from '@/i18n';
import { linksData, linksData2 } from '@/config';

import AppContent from '@/components/AppContent.vue';

import LogoFooter from '@/assets/footer-logo2.png';
import LogoFooter1 from '@/assets/footer-logo1.png';
import LogoAtom from '@/assets/atom-logo.svg';

// 公众号、小助手
import CodeTitleXzs from '@/assets/img-xzs.png';
import CodeTitleGzh from '@/assets/img-gzh.png';
import CodeImgXzs from '@/assets/code-xzs.png';
import CodeImgZgz from '@/assets/code-zgz.png';

const props = defineProps({
  lang: {
    type: String as PropType<'zh' | 'en'>,
    default: 'zh',
  },
  target: {
    type: String,
    default: '_blank',
  },
});

const { t, locale } = i18n.global;

// 公众号、小助手
const footerCodeList = [
  {
    img: CodeTitleGzh,
    code: CodeImgZgz,
    label: t('common.FOOTER.QR_ASSISTANT'),
  },
  {
    img: CodeTitleXzs,
    code: CodeImgXzs,
    label: t('common.FOOTER.QR_CODE'),
  },
];

watch(
  () => props.lang,
  (val) => {
    locale.value = val as 'zh' | 'en';
  },
  { immediate: true }
);
</script>
<script lang="ts">
export default {
  name: 'AppFooter',
};
</script>

<template>
  <div class="footer">
    <AppContent :pc-top="0" :mobile-top="0">
      <div class="atom">
        <p class="atom-text">{{ t('common.FOOTER.ATOM_TEXT') }}</p>
        <a href="https://openatom.cn" target="_blank">
          <img :src="LogoAtom" class="atom-logo" alt="" />
        </a>
      </div>
    </AppContent>
    <div class="footer-content">
      <AppContent :pc-top="0" :mobile-top="0">
        <div class="inner">
          <div class="footer-logo">
            <img class="show-pc" :src="LogoFooter" alt="" />
            <img class="show-mo" :src="LogoFooter1" alt="" />
            <p>
              <a
                class="email"
                href="mailto:contact@openeuler.io"
                target="_blank"
              >
                contact@openeuler.io
              </a>
            </p>
          </div>
          <div class="footer-option">
            <div class="footer-option-item">
              <a
                v-for="link in linksData2[lang]"
                :target="target"
                :key="link.URL"
                :href="link.URL"
                class="link"
                >{{ link.NAME }}</a
              >
            </div>
            <p class="copyright">
              {{
                t('common.FOOTER.COPY_RIGHT', {
                  year: new Date().getFullYear(),
                })
              }}
            </p>
            <p class="license">
              <span>{{ t('common.FOOTER.LICENSED_1') }}</span>
              {{ t('common.FOOTER.LICENSED_2') }}
            </p>
          </div>
          <div class="footer-right">
            <div v-if="lang === 'zh'" class="code-box">
              <div
                v-for="(item, index) in footerCodeList"
                :key="index"
                class="code-pop"
              >
                <img :src="item.img" class="code-img" alt="" />
                <div class="code-layer">
                  <img :src="item.code" alt="" />
                  <p class="txt">{{ item.label }}</p>
                </div>
              </div>
            </div>
            <div class="footer-links" :class="{ iszh: lang === 'zh' }">
              <a
                v-for="item in linksData[lang]"
                :key="item.path"
                :href="item.path"
                :style="{ height: `${item.height}px` }"
                class="links-logo"
                target="_blank"
              >
                <img :src="item.logo" alt="" />
              </a>
            </div>
          </div>
        </div>
      </AppContent>
    </div>
  </div>
</template>

<style lang="scss" scoped>
$color: #fff;
.footer {
  background: rgba(18, 18, 18);
  &.migration {
    margin-left: 300px;
    @media (max-width: 1100px) {
      margin-left: 0;
    }
  }
  :deep(.app-content) {
    padding-bottom: 0;
  }
  .atom {
    text-align: center;
    padding: var(--o-spacing-h3) 0 var(--o-spacing-h4);
    position: relative;
    border-bottom: 1px solid rgba(229, 229, 229, 0.12);
    @media (max-width: 1440px) {
      padding: var(--o-spacing-h4) 0;
    }

    .atom-text {
      font-size: var(--o-font-size-h6);
      font-weight: 400;
      color: $color;
      line-height: var(--o-line-height-h6);
      @media (max-width: 1440px) {
        font-size: var(--o-font-size-text);
        line-height: var(--o-line-height-text);
      }
    }
    .atom-logo {
      height: 48px;
      margin-top: 16px;
      @media (max-width: 1100px) {
        height: 30px;
      }
    }
  }

  .footer-content {
    background: url('@/assets/footer-bg.png') no-repeat bottom center;
    @media (max-width: 767px) {
      background: url('@/assets/footer-bg-mo.png') no-repeat bottom center;
    }
    .inner {
      display: flex;
      align-items: end;
      justify-content: space-between;
      padding: 18px 0 32px;
      position: relative;
      min-height: 118px;
      @media (max-width: 1436px) {
        padding: var(--o-spacing-h4) 0;
        flex-direction: column;
        justify-content: space-between;
        align-items: center;
      }
    }
  }
  .footer-logo {
    flex: 1;
    img {
      height: 46px;
    }
    .show-pc {
      display: block;
    }
    .show-mo {
      display: none;
    }
    @media (max-width: 1436px) {
      text-align: center;
      margin: 16px 0;
      .show-pc {
        display: none;
      }
      .show-mo {
        display: inline-block;
        height: 20px;
      }
    }
  }

  .copyright {
    font-size: var(--o-font-size-text);
    color: $color;
    margin-top: var(--o-spacing-h5);
    @media (max-width: 1436px) {
      font-size: var(--o-font-size-tip);
      line-height: var(--o-line-height-tip);
      margin-top: var(--o-spacing-h8);
    }
  }
  .license {
    font-size: var(--o-font-size-text);
    color: $color;
    margin-top: var(--o-spacing-h5);
    span {
      color: var(--o-color-text-secondary);
    }
    @media (max-width: 1400px) {
      font-size: var(--o-font-size-tip);
      line-height: var(--o-line-height-tip);
      margin-top: var(--o-spacing-h8);
    }
  }

  .footer-option {
    text-align: center;
    .link {
      color: $color;
      font-size: var(--o-font-size-text);
      display: inline-block;
      padding: 0 var(--o-spacing-h6);
      border-right: 1px solid $color;
      &:last-child {
        border-right: 0;
      }
      @media (max-width: 1436px) {
        font-size: var(--o-font-size-tip);
        line-height: var(--o-line-height-tip);
        padding: 0 var(--o-spacing-h9);
      }
    }
    @media (max-width: 1436px) {
      order: -1;
    }
  }

  .footer-right {
    flex: 1;
    .code-box {
      display: flex;
      justify-content: right;
      gap: 16px;
      margin-bottom: 16px;
      .code-pop {
        cursor: pointer;
        position: relative;
        height: 20px;
        display: block;
        > img {
          height: 100%;
          object-fit: cover;
        }
        .code-layer {
          position: absolute;
          top: -105px;
          left: -32px;
          z-index: 99;
          display: none;
          background: #fff;
          padding: 6px;
          img {
            width: 78px;
            height: 78px;
          }
          .txt {
            font-size: 12px;
            color: $color;
            display: none;
          }
          &::after {
            border: 10px solid transparent;
            content: '';
            border-top-color: #fff;
            position: absolute;
            bottom: -20px;
            left: 50%;
            transform: translateX(-50%);
            display: block;
          }
          @media (max-width: 800px) {
            display: block;
            position: initial;
            background: none;
            padding: 0;
            text-align: center;
            &::after {
              display: none !important;
            }
            .txt {
              display: block;
            }
          }
        }
        &:hover {
          .code-layer {
            display: block;
          }
        }
        @media (max-width: 800px) {
          height: auto;
          > img {
            display: none;
          }
        }
      }
      @media (max-width: 1436px) {
        justify-content: center;
      }
      @media (max-width: 1100px) {
        margin-top: 24px;
      }
    }
    .footer-links {
      display: flex;
      justify-content: right;
      align-items: center;
      gap: 16px;
      .links-logo {
        display: flex;
        height: 16px;
        img {
          height: 100%;
          object-fit: cover;
        }
      }
      @media (max-width: 1100px) {
        justify-content: center;
      }
      @media (max-width: 800px) {
        display: flex;
        text-align: center;
        .img {
          height: 16px;
        }
      }
      &.iszh {
        gap: 10px;
        .links-logo {
          height: 14px;

          &:first-child {
            height: 18px;
          }
        }
        @media (max-width: 800px) {
          display: grid;
          grid-template-columns: repeat(3, 1fr);
          text-align: center;
          margin-top: 40px;
          .img {
            height: 16px;
          }
        }
      }
    }

    p {
      color: $color;
      font-size: var(--o-font-size-tip);
      margin-top: var(--o-spacing-h8);
    }
  }

  .email {
    color: $color;
    font-size: var(--o-font-size-text);
    @media (max-width: 1436px) {
      font-size: var(--o-font-size-tip);
    }
  }
}
</style>
